package com.hzit.controller;

import com.hzit.annotation.RequiresPermissions;
import com.hzit.entity.User;
import com.hzit.service.IUserService;
import com.hzit.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2023-10-27
 */
@RestController
@RequestMapping("/user")
@RefreshScope           // 自动刷新配置，结合系统配置文件中的refresh这个属性才能起作用。
public class UserController {

	@Autowired
	private IUserService userService;
	@Value("${student.sname}")
	private String sname;
	@Value("${student.age}")
	private int age;
	@Value("${server.port}")
	public int port;
	// @Resource
	// private LoadBalancerClient client;
	@Value("${classes.cname}")
	private String cname;

	@GetMapping("/list")
	@RequiresPermissions("user:list")
	public R list(){
		// URI uri = client.choose("hzit-manager").getUri();
		return R.ok(userService.list());
	}

	@GetMapping("/getConfig")
	public R<Map> getConfig(){
		Map<String,Object> map = new HashMap<>();
		map.put("sname",sname);
		map.put("age",age);
		map.put("cname",cname);
		return R.ok(map);
	}

	@GetMapping("/getPort")
	public R getPort(){
		Map<String,Object> map = new HashMap<>();
		map.put("port",port);
		return R.ok(map);
	}
}
